package com.buli.blmall.admin.system.service;

import com.buli.blmall.admin.system.entity.SysRole;
import com.buli.blmall.admin.system.vo.SysRoleVO;
import com.buli.blmall.admin.system.mapper.SysRoleMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;

/**
 * <p>
 * 角色 服务类
 * </p>
 *
 * @author buli
 * @since 2025-02-27
 */
@Service
public class SysRoleService extends ServiceImpl<SysRoleMapper, SysRole> {

    /**
     * 查询角色详情
     *
     * @param id
     * @return 角色详情
     */
    public SysRoleVO info(Long id) {
        return BeanUtil.copyProperties(getById(id), SysRoleVO.class );
    }

    /**
     * 查询角色集合
     *
     * @param sysRoleVo
     * @return 角色集合
     */
    public List<SysRoleVO> queryList(SysRoleVO sysRoleVo) {
        LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
        List<SysRole> list = list(queryWrapper);
        return BeanUtil.copyToList(list, SysRoleVO.class );
    }

    /**
     * 新增角色
     * @param sysRoleVo
     * @return boolean
     */
    public boolean add(SysRoleVO sysRoleVo) {
        SysRole sysRole = BeanUtil.copyProperties(sysRoleVo, SysRole.class );
        return save(sysRole);
    }

    /**
     * 编辑角色
     * @param sysRoleVo
     * @return boolean
     */
    public boolean edit(SysRoleVO sysRoleVo) {
        SysRole sysRole = BeanUtil.copyProperties(sysRoleVo, SysRole.class );
        return updateById(sysRole);
    }

    /**
     * 删除角色
     * @param id
     * @return boolean
     */
    public boolean delete(Long id) {
        return removeById(id);
    }

    /**
     * 根据id批量查询角色集合
     * @param idList
     * @return
     */
    public List<SysRole> getByIds(List<Long> idList) {
        return getBaseMapper().selectBatchIds(idList);
    }
}
